package com.wmeimob.fastboot.jiubei.controller;

import com.github.pagehelper.PageInfo;
import com.wmeimob.fastboot.core.context.PageContext;
import com.wmeimob.fastboot.jiubei.entity.ShopGoodsClassify;
import com.wmeimob.fastboot.jiubei.service.ShopGoodsClassifyService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @className ShopGoodsClassifyController
 * @description 【商城商品分类】控制器
 * @author wjt
 * @date Wed Aug 26 21:50:57 CST 2020
 * @version 1.0
 **/
@RestController
@RequestMapping("shopGoodsClassify")
@Slf4j
public class ShopGoodsClassifyController {

    @Resource
    private ShopGoodsClassifyService shopGoodsClassifyService;




    /**
     * 商城商品分类分页查询
     * @param shopGoodsClassify
     * @return
     */
    @GetMapping
    public PageInfo queryForShopGoodsClassify(ShopGoodsClassify shopGoodsClassify){
        PageContext.startPage();
        return new PageInfo<ShopGoodsClassify>(shopGoodsClassifyService.findAll(shopGoodsClassify));
    }

    /**
     * 查询一级类目
     */
    @GetMapping("/queryByFirst")
    public List<ShopGoodsClassify> selectListByPidFirst() {
        return shopGoodsClassifyService.selectListByPidFirst();
    }
    /**
     * 根据上级分类id查询下级分类列表
     *
     * @param id
     * @return
     */
    @GetMapping("{id}")
    public List<ShopGoodsClassify> selectListByPid(@PathVariable("id") Integer id) {
        ShopGoodsClassify goodsClassify = new ShopGoodsClassify();
        goodsClassify.setId(id);
        return shopGoodsClassifyService.selectListByPid(goodsClassify);
    }

    /**
     * 商城商品分类查询-<通过id查询>
     * @param id
     * @return
     */
   /* @GetMapping("/{id}")
    public ShopGoodsClassify queryForShopGoodsClassifyById(@PathVariable("id") Object id){
            return  shopGoodsClassifyService.queryShopGoodsClassifyById(id);
    }*/


    /**
     * 商城商品分类添加
     * @param shopGoodsClassify
     * @return
     */
    @PostMapping
    public void insertForShopGoodsClassify(@RequestBody ShopGoodsClassify shopGoodsClassify){
            shopGoodsClassifyService.addShopGoodsClassify(shopGoodsClassify);    
    }


    /**
     * 商城商品分类修改
     * @param shopGoodsClassify
     * @return
     */
    @PutMapping
    public void updateForShopGoodsClassify(@RequestBody ShopGoodsClassify shopGoodsClassify){
            shopGoodsClassifyService.modifyShopGoodsClassify(shopGoodsClassify);  
    }

    /**
     * 商城商品分类删除
     * @param id
     * @return
     */
    @DeleteMapping("/{id}")
    public void removeForShopGoodsClassify(@PathVariable("id") Object id){
            shopGoodsClassifyService.removeShopGoodsClassify(id);
    }
}
